package com.hxkcloud.nurse.fragments;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hyphenate.easeui.EaseConstant;
import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.YjhApplication;
import com.hxkcloud.nurse.activitys.ChatFragmentActivity;
import com.hxkcloud.nurse.activitys.MessageMainActivity;
import com.hxkcloud.nurse.activitys.MonitorChart1Activity;
import com.hxkcloud.nurse.activitys.PatientBetterPlanActivity;
import com.hxkcloud.nurse.activitys.PatientInfoActivity;
import com.hxkcloud.nurse.activitys.SearchUserManagerActivity;
import com.hxkcloud.nurse.adapter.FilterAdapter;
import com.hxkcloud.nurse.adapter.FilterListAdapter;
import com.hxkcloud.nurse.adapter.UsermanagerGridViewAdapter;
import com.hxkcloud.nurse.adapter.UsermanagerGridViewAdapterHuanBing;
import com.hxkcloud.nurse.adapter.UsermanagerGridViewAdapterZhuzhen;
import com.hxkcloud.nurse.beans.DepartmentBean;
import com.hxkcloud.nurse.beans.FilterBean;
import com.hxkcloud.nurse.beans.FilterItem;
import com.hxkcloud.nurse.beans.FilterListBean;
import com.hxkcloud.nurse.beans.FilterPatientBean;
import com.hxkcloud.nurse.beans.UserManagerBean;
import com.hxkcloud.nurse.beans.UserManagerInfo;
import com.hxkcloud.nurse.beans.resultbeans.ObjectResultBean;
import com.hxkcloud.nurse.dborm.DepartmentDao;
import com.hxkcloud.nurse.popup.DatePopWindow;
import com.hxkcloud.nurse.request.MessageCode;
import com.hxkcloud.nurse.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.nurse.utils.BrightnessUtils;
import com.hxkcloud.nurse.utils.ImageUtil;
import com.hxkcloud.nurse.views.MyGridView;
import com.hxkcloud.nurse.views.pulltorefreshlayout.PullToRefreshLayout;
import com.hxkcloud.nurse.views.pulltorefreshlayout.PullableRecyclerView;
import com.hxkcloud.nurse.adapter.UserManagerAdapter;

import android.support.v7.widget.LinearLayoutManager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户管理
 */
public class UserManagerFragment extends BaseFragment implements View.OnClickListener, PullToRefreshLayout.OnRefreshListener, UserManagerAdapter.ResultSelectedListener {

    private View view;
    private LinearLayout ll_title;
    private ImageView iv_search;
    private TextView tv_title;
    private ImageView iv_message;
    private ImageView iv_msgpoint;
    private TextView tv_count;//患者总数
    private LinearLayout ll_empty;
    private LinearLayout ll_info;
    private LinearLayout ivgLayout;//导航布局
    private LinearLayout display1Layout;
    private LinearLayout display4Layout;
    private LinearLayout display5Layout;
    private TextView display1TV;
    private TextView display4TV;
    private ImageView display1IV;
    private ImageView display4IV;
    private View middleView1;
    private View middleView2;
    private PopupWindow allPopup;//选择全部
    private PopupWindow showPopWalk;
    private ListView allListView;
    private FilterListAdapter allAdapter;
    private View allWholeView;
    private DatePopWindow datePopup;
    private TextView tv_chongzhi;
    private TextView tv_sure;
    private View  viewsback;
    private TextView tv_zhili;
    private TextView tv_zhuzhen;
    private TextView tv_huanbing;
    private TextView tv_fourthName;//第四个筛选条件name
    private TextView tv_fifthName;//第五个筛选条件name
    private MyGridView gridView_zhili;
    private MyGridView gridView_zhuzhen;
    private MyGridView gridView_huanbing;
    private MyGridView gridview_fourth;//第四个筛选的gridview
    private MyGridView gridview_fifth;//第五个筛选的gridview
//    private String [] data_zhili = new String[]{ "正常","轻度功能障碍","中度功能障碍","重度功能障碍"};
//    private String[] data_zhuzhen = {"三组","四组","五组","六组"};
//    private String[] data_huanbing = {"脑出血","脑血管狭窄","脑梗死",
//            "高血压","左锁骨下动脉闭塞","待定",
//            "陈旧性脑出血","大脑前动脉起始狭窄右","后循环缺血","静脉窦血栓"};
    private List<FilterItem> list_zhili;
    private List<FilterItem> list_zhuzhen;
    private List<FilterItem> list_huanbing;
    private List<FilterItem> list_fourth;//第四個筛选集合
    private List<FilterItem> list_fifth;//第五個筛选集合
    private List<String> group;
    private UsermanagerGridViewAdapter gridViewAdapter_zhili;
    private UsermanagerGridViewAdapterZhuzhen gridViewAdapter_zhuzhen;
    private UsermanagerGridViewAdapterHuanBing gridViewAdapter_huanbing;
    private FilterAdapter fourthAdatper;//第四个筛选条件
    private FilterAdapter fifthAdatper;//第五个筛选条件
    private PullToRefreshLayout refreshLayout;
    private PullableRecyclerView recycleView;
    private List<UserManagerBean> userManagerInfoList;
    private UserManagerAdapter adapter;
    private String date = "";//时间   格式：时间戳
    private String dateKind = "";//时间类型
    private int pageIndex = 1;
    private int pageSize = 15;
    private boolean isLoadMore = false;// 是否加载更多
    private ObjectResultBean<UserManagerInfo> resultBean;
    private int totalCount = 0;
    private List<FilterItem> filterItems;
    private ObjectResultBean<FilterListBean> filterBean;
    private List<FilterBean> listBeans;//所有的筛选条件数组 网络返回
    private boolean isDisplay4 = false;
    private int clickNum = 1;//1 2 3
    private String display1Default = "";
    private String display2Default = "";
    private String display3Default = "";
    private String display4Default = "";
    private String display1Id = "";
    private String display2Id = "";
    private String display3Id = "";
    private String display4Id = "";
    private String display1Type = "";
    private String display2Type = "";
    private String display3Type = "";
    private String display4Type = "";
    private List<FilterPatientBean> filterList;//筛选条件集合
    private List<FilterPatientBean> filterList_zhili;//筛选条件集合
    private List<FilterPatientBean> filterList_huanbing;//筛选条件集合
    private List<FilterPatientBean> filterList_fenzhu;//筛选条件集合
    private List<FilterPatientBean> filterList_fourth;//筛选条件集合
    private List<FilterPatientBean> filterList_fifth;//筛选条件集合
    private boolean isChanke = false;
    private boolean isDisplay1Click = true;
    private boolean isDisplay4Click = true;
    private TextView msg_number;
    private boolean showIcon;
    private  Map<Integer,Boolean> map_zhili;
    private  Map<Integer,Boolean> map_huanbing;
    private  Map<Integer,Boolean> map_zhuzhen;
    private int first = 4;
    private int second = 6;
    private int third = 1;
    private int fourth = 3;
    private int fifth = 2;
    private int status = 0;//住院状态


    public UserManagerFragment() {
        super();
    }

    public void showPoint(boolean show, String jpushType) {
        showIcon = show;
        if (iv_msgpoint != null) {
            if (show) {
                iv_msgpoint.setVisibility(View.VISIBLE);
            } else {
                iv_msgpoint.setVisibility(View.INVISIBLE);
            }
        }
        if ((!TextUtils.isEmpty(jpushType)) && (jpushType.equals("3"))) {
            if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                initData();
                ll_empty.setVisibility(View.GONE);
                ll_info.setVisibility(View.VISIBLE);
            }
        }
        YjhApplication.getInstance().showMsg(msg_number);
    }

    public void jpushRefreshPatients() {
      /*  if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
           // initData();
            ll_empty.setVisibility(View.GONE);
            ll_info.setVisibility(View.VISIBLE);
        }*/
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERNEWLIST_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    resultBean = (ObjectResultBean<UserManagerInfo>) msg.obj;
                    totalCount = Integer.parseInt(resultBean.getData().getTotalCount());
                    if (resultBean.getData().getList().size() == 0) {
                        if (isLoadMore) {
                            refreshLayout.loadmoreFinish(PullToRefreshLayout.SUCCEED);
                        } else {
                            userManagerInfoList.clear();
                            adapter.setData(userManagerInfoList);
                            refreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
                        }
                    } else {
                        if (isLoadMore) {

                        } else {
                            userManagerInfoList.clear();
                        }
                        userManagerInfoList.addAll(resultBean.getData().getList());
                        Log.i("--infoList-->","userManagerInfoList:"+userManagerInfoList.toString());
                        adapter.setData(userManagerInfoList);
                        if (isLoadMore) {
                            refreshLayout.loadmoreFinish(PullToRefreshLayout.SUCCEED);
                        } else {
                            refreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
                        }
                    }
                    if (totalCount > 0) {
                        tv_count.setText(totalCount + "人");
                        tv_count.setVisibility(View.VISIBLE);
                    } else {
                        tv_count.setVisibility(View.GONE);
                    }
                }

                break;
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERNEWLIST_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }
                break;

            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERLIST_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    filterBean = (ObjectResultBean<FilterListBean>) msg.obj;
                    listBeans = filterBean.getData().getList();
                    Log.i("-----listBeanss---->",listBeans.toString());
                    if (listBeans != null && listBeans.size() > 0) {
                        for (int i = 0 ; i < listBeans.size() ; i++)
                        {
                            if("状态".equals(listBeans.get(i).getFilterName()))
                            {
                                status = i;
                                //筛选条件 全部 在院 出院
                                display1Default = listBeans.get(i).getFilterName();
                                display1Id = listBeans.get(i).getFilterId();
                                display1Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display1TV.setText(display1Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display1TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                listBeans.get(i).getFilterList().get(j).setIsSelect(true);
                                                display1TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display1Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display1Id);
                                                bean.setFilterName(display1Default);
                                                bean.setFilterType(display1Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display1TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display1TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            }
                            if("出院时间".equals(listBeans.get(i).getFilterName()))
                            {
                                display4Default = listBeans.get(i).getFilterName();
                                display4Id = listBeans.get(i).getFilterId();
                                display4Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display4TV.setText(display4Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display4TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                display4TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display4Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display4Id);
                                                bean.setFilterName(display4Default);
                                                bean.setFilterType(display4Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display4TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display4TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            }
                        }
                        loading();
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        //获取filterList里的数据
                        Log.i("---DDD-->","listBeans:"+listBeans.toString());
                        //解析筛选数据
                        for(int i = 0 ; i < listBeans.size() ; i++)
                        {
                            //自理能力
                            if("自理能力".equals(listBeans.get(i).getFilterName()))
                            {
                                first = i;
                            }
                            //主诊团队
                            if("主诊团队".equals(listBeans.get(i).getFilterName()))
                            {
                                second = i ;
                            }
                            //诊断
                            if("诊断".equals(listBeans.get(i).getFilterName()))
                            {
                                third = i;
                            }
                            //是否合并房颤
                            if("是否合并房颤".equals(listBeans.get(i).getFilterName()))
                            {
                                fourth = i;
                            }
                            //既往史
                            if("既往史".equals(listBeans.get(i).getFilterName()))
                            {
                                fifth = i;
                            }
                        }

                        //第一个gridVie数据
                        for (int i = 0 ; i < listBeans.get(first).getFilterList().size();i++)
                        {
                            list_zhili.add(listBeans.get(first).getFilterList().get(i));
                            map_zhili.put(i,false);
                        }
                        //第二个gridVie数据
                        for (int i=0;i<listBeans.get(second).getFilterList().size();i++)
                        {
                            list_zhuzhen.add(listBeans.get(second).getFilterList().get(i));
                            map_zhuzhen.put(i,false);
                        }
                        //第三个gridVie数据
                        for (int i=0;i<listBeans.get(third).getFilterList().size();i++)
                        {
                            list_huanbing.add(listBeans.get(third).getFilterList().get(i));
                            map_huanbing.put(i,false);
                        }
                        //第四个gridView 数据
                        for (int i=0;i<listBeans.get(fourth).getFilterList().size();i++)
                        {


                            if("房颤".equals(listBeans.get(fourth).getFilterList().get(i).getItemName()))
                            {
                                listBeans.get(fourth).getFilterList().get(i).setIsSelect(false);
                                list_fourth.add(listBeans.get(fourth).getFilterList().get(i));
                            }


                        }
                        //第五个gridView 数据
                        for (int i=0;i<listBeans.get(fifth).getFilterList().size();i++)
                        {
                            listBeans.get(fifth).getFilterList().get(i).setIsSelect(false);
                            list_fifth.add(listBeans.get(fifth).getFilterList().get(i));
                        }

                        showPopDate5();
//                        list_huanbing = listBeans.get(2).getFilterList();
                        //设置标题
                        // 1
                        tv_zhili.setText(listBeans.get(first).getFilterName());
                        // 2
                        tv_zhuzhen.setText(listBeans.get(second).getFilterName());
                        // 3
                        tv_huanbing.setText(listBeans.get(third).getFilterName());
                        //4
                        tv_fourthName.setText(listBeans.get(fourth).getFilterName());
                        //5
                        tv_fifthName.setText(listBeans.get(fifth).getFilterName());

                    } else
                    {
                        ivgLayout.setVisibility(View.GONE);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                    }

                }
                break;
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERLIST_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg((String) msg.obj);
                }
                break;

        }

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.fragment_layout_usermanager, container, false);
        userManagerInfoList = new ArrayList<>();
        listBeans = new ArrayList<>();
        filterItems = new ArrayList<>();
        filterList = new ArrayList<>();
        filterList_zhili = new ArrayList<>();
        filterList_huanbing = new ArrayList<>();
        filterList_fenzhu = new ArrayList<>();
        filterList_fourth = new ArrayList<>();
        filterList_fifth = new ArrayList<>();
        list_zhuzhen = new ArrayList<>();
        list_huanbing = new ArrayList<>();
        list_zhili = new ArrayList<>();
        list_fourth = new ArrayList<>();
        list_fifth = new ArrayList<>();

        group = new ArrayList<>();
        map_zhili = new HashMap<>();
        map_huanbing = new HashMap<>();
        map_zhuzhen = new HashMap<>();
        initView();
        initListener();
        initData();
        YjhApplication.patientIsStatusChange = false;
        return view;

    }

    @Override
    public void onResume() {
        super.onResume();
        if (TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            ll_empty.setVisibility(View.VISIBLE);
            ll_info.setVisibility(View.GONE);
        } else {
            isDisplay4 = false;
            if (YjhApplication.patientIsStatusChange)
                filterPatientInfo();
            YjhApplication.patientIsStatusChange = false;
            ll_empty.setVisibility(View.GONE);
            ll_info.setVisibility(View.VISIBLE);
        }


        YjhApplication.getInstance().showMsg(msg_number);
    }

    @Override
    protected void initView() {

        ll_title = (LinearLayout) view.findViewById(R.id.ll_title);
        iv_search = (ImageView) view.findViewById(R.id.iv_title_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title_title);
        iv_message = (ImageView) view.findViewById(R.id.iv_title_func);
        iv_msgpoint = (ImageView) view.findViewById(R.id.iv_title_point);

        msg_number = (TextView) view.findViewById(R.id.msg_number);

        setTitlePadding(ll_title);
        iv_search.setVisibility(View.VISIBLE);
        iv_search.setImageResource(R.mipmap.nav_search);
        tv_title.setText(getResources().getText(R.string.usermanger_text));
        iv_message.setVisibility(View.VISIBLE);
        iv_message.setImageResource(R.mipmap.nav_message);
        iv_search.setOnClickListener(this);
        iv_message.setOnClickListener(this);

        tv_count = (TextView) view.findViewById(R.id.usermanager_count);
        ll_empty = (LinearLayout) view.findViewById(R.id.ll_department_empty);
        ll_info = (LinearLayout) view.findViewById(R.id.ll_usermanager_info);

        ivgLayout = (LinearLayout) view.findViewById(R.id.usermanager_layout_ivg);

        display1Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display1);
        display4Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display4);
        display5Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display5);
        display1TV = (TextView) view.findViewById(R.id.usermanager_tv_display1);
        display4TV = (TextView) view.findViewById(R.id.usermanager_tv_display4);
        display1IV = (ImageView) view.findViewById(R.id.usermanager_iv_display1);

        middleView1 = (View) view.findViewById(R.id.usermanager_view_view1);
        middleView2 = (View) view.findViewById(R.id.usermanager_view_view2);
        display4IV = (ImageView) view.findViewById(R.id.usermanager_iv_display4);



        refreshLayout = (PullToRefreshLayout) view.findViewById(R.id.usermanager_refreshlayout);
        recycleView = (PullableRecyclerView) view.findViewById(R.id.usermanager_recyclerview);

        RelativeLayout.LayoutParams lp_count = new RelativeLayout.LayoutParams(screenWidth / 10, screenWidth / 10);
        lp_count.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        lp_count.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        lp_count.bottomMargin = ImageUtil.dip2px(15, mContext);
        lp_count.rightMargin = ImageUtil.dip2px(10, mContext);
        tv_count.setLayoutParams(lp_count);

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(mLayoutManager);
        adapter = new UserManagerAdapter(getActivity(), userManagerInfoList, recycleView, this, screenWidth, loginInfo.getDepartmentId());
        recycleView.setAdapter(adapter);

        initAllPopup();
//        showPopDate5();
        if (showIcon) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    protected void initListener() {

        iv_search.setOnClickListener(this);

        display1Layout.setOnClickListener(this);
        display4Layout.setOnClickListener(this);
        display5Layout.setOnClickListener(this);
        iv_message.setOnClickListener(this);
        refreshLayout.setOnRefreshListener(this);
    }

    @Override
    protected void initData() {
        DepartmentDao dao = new DepartmentDao(mContext);
        List<DepartmentBean> beans = dao.getDepartment();
        if (beans != null) {
            for (int i = 0; i < beans.size(); i++) {
                if ((beans.get(i).getDepartmentId() + "").equals(loginInfo.getDepartmentId())) {
                    if ("0".equals(beans.get(i).getType())) {
                        isChanke = true;
                    }
                    break;
                }
            }
        }


        adapter = new UserManagerAdapter(getActivity(), userManagerInfoList, recycleView, this, screenWidth, loginInfo.getDepartmentId());
        recycleView.setAdapter(adapter);
        loading();
        YiJiaHuNetWorkUtils.getPatientFilterList(loginInfo.getDepartmentId(), handler);
        pageIndex = 1;

    }

    //筛选用户管理信息
    public void filterPatientInfo() {
        //isLoadMore = false;
        //pageIndex = 1;
        loading();

        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
     //   YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,"1",group, "", pageIndex, pageSize, handler);
    }

    private void setInitPopup() {

        display1TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display1IV.setImageResource(R.mipmap.tab_arrow);
        display4TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display4IV.setImageResource(R.mipmap.tab_arrow);




    }

    private void initAllPopup() {
        allPopup = new PopupWindow(getActivity());
        View allView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_layout_kind, null);
        allPopup.setContentView(allView);

        allPopup.setWidth(screenWidth);
        allPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        allPopup.setFocusable(true);
        allPopup.setTouchable(true);
        allPopup.setOutsideTouchable(true);
        allPopup.setBackgroundDrawable(new ColorDrawable(0x00000000));


        allListView = (ListView) allView.findViewById(R.id.kind_listview);
        allAdapter = new FilterListAdapter(getActivity(), filterItems);
        allListView.setAdapter(allAdapter);
        allListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < filterItems.size(); i++) {
                    if (i == position) {
                        filterItems.get(i).setIsSelect(true);
                    } else {
                        filterItems.get(i).setIsSelect(false);
                    }
                }
                FilterPatientBean bean = new FilterPatientBean();
                bean.setDate("");
                bean.setDateKind("");
                if (clickNum == 1) {
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display1Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display1TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display1TV.setText(displayName + "...");
                        } else {
                            display1TV.setText(name);
                        }
                    }
                    if ("2".equals(display1Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    display1IV.setImageResource(R.mipmap.tab_arrow);
                    //
                    removeFilterListItem(display1Id);
                    bean.setFilterId(display1Id);
                    bean.setFilterName(display1Default);
                    bean.setFilterType(display1Type);
                    bean.setItemId(filterItems.get(position).getItemId());

                } else if (clickNum == 2) {
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display2Type) && "-1".equals(filterItems.get(position).getItemId())) {
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                        } else {
                        }
                    }
                    if ("2".equals(display2Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        display4Layout.setEnabled(true);
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);

                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }

                    removeFilterListItem(display2Id);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                } else if (clickNum == 3) {
                    String name = filterItems.get(position).getItemName();

                    if ("5".equals(display3Type) && "-1".equals(filterItems.get(position).getItemId())) {
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                        } else {
                        }
                    }
                    if ("2".equals(display3Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    removeFilterListItem(display3Id);
                    bean.setFilterId(display3Id);
                    bean.setFilterName(display3Default);
                    bean.setFilterType(display3Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                } else if (clickNum == 4) {
                    isDisplay4 = true;
//                    display4TV.setText(filterItems.get(position).getItemName());
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display4Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display4TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display4TV.setText(displayName + "...");
                        } else {
                            display4TV.setText(name);
                        }
                    }
                    if ("2".equals(display4Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    display4IV.setImageResource(R.mipmap.tab_arrow);
                    removeFilterListItem(display4Id);
                    bean.setFilterId(display4Id);
                    bean.setFilterName(display4Default);
                    bean.setFilterType(display4Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                }
                filterList.add(bean);

                allAdapter.notifyDataSetChanged();
                allPopup.dismiss();
                loading();
               // YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                Log.i("------------>","fenzhu:"+filterList_fenzhu.size()+"huangbing:"+filterList_huanbing.size()+"zhili:"+filterList_zhili.size()+"");
                YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
            }
        });
        allAdapter.setDisplayListener(new FilterListAdapter.DisplayListener() {
            @Override
            public void onDisplay(int position) {

            }
        });

        allWholeView = (View) allView.findViewById(R.id.kind_view_whole);
        allWholeView.setOnClickListener(this);

        allPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                display1IV.setImageResource(R.mipmap.tab_arrow);
                display4IV.setImageResource(R.mipmap.tab_arrow);
            }
        });
    }

    private void removeFilterTimeItem() {
        if (filterList != null && filterList.size() > 0) {
            for (int i = 0; i < filterList.size(); i++) {
                if (filterList.get(i).getFilterName().equals(mContext.getResources().getString(R.string.usermanger_text_time))) {
                    filterList.remove(i);
                }
            }
        }
    }

    private void removeFilterListItem(String kindId) {
        if (filterList != null && filterList.size() > 0) {
            for (int i = 0; i < filterList.size(); i++) {
                if (kindId.equals(filterList.get(i).getFilterId())) {
                    filterList.remove(i);
                }
            }
        }
    }
    private void removeFilterList_zhiliItem(String kindId){
        if (filterList_zhili!=null&&filterList_zhili.size()>0){
            for (int i = 0; i < filterList_zhili.size(); i++) {
                if (kindId.equals(filterList_zhili.get(i).getFilterId())) {
                    filterList_zhili.remove(i);
                }
            }
        }
    }
    private void removeFilterList_huanbingItem(String kindId){
        if (filterList_huanbing!=null&&filterList_huanbing.size()>0){
            for (int i = 0; i < filterList_huanbing.size(); i++) {
                if (kindId.equals(filterList_huanbing.get(i).getFilterId())) {
                    filterList_huanbing.remove(i);
                }
            }
        }
    }
    private void removeFilterList_fenzhuItem(String kindId){
        if (filterList_fenzhu!=null&&filterList_fenzhu.size()>0){
            for (int i = 0; i < filterList_fenzhu.size(); i++) {
                if (kindId.equals(filterList_fenzhu.get(i).getFilterId())) {
                    filterList_fenzhu.remove(i);
                }
            }
        }
    }
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.usermanager_layout_display1://在院
                setInitPopup();
                clickNum = 1;
                display1IV.setImageResource(R.mipmap.tab_arrow_down_grenn);
                filterItems = listBeans.get(status).getFilterList();
                allAdapter.setData(filterItems);
                allPopup.showAsDropDown(ivgLayout);
                break;
            case R.id.usermanager_layout_display4://日期
                if (!"在院".equals(display1TV.getText().toString()))
                {
                    setInitPopup();
                    clickNum = 4;
                    display4IV.setImageResource(R.mipmap.tab_arrow_up_green);
                    showPopDate4();
                }
                break;
            case R.id.usermanager_layout_display5:
                BrightnessUtils.lightOff(getActivity());
                display4IV.setImageResource(R.mipmap.tab_arrow);
                showPopWalk.showAtLocation(ll_title, Gravity.RIGHT,0,0);
                break;
            case R.id.kind_view_whole:
                display1IV.setImageResource(R.mipmap.tab_arrow);
                allPopup.dismiss();
                break;
            case R.id.iv_title_back:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent intent = new Intent(getActivity(), SearchUserManagerActivity.class);
                    startActivity(intent);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
            case R.id.iv_title_func:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent iM = new Intent(mContext, MessageMainActivity.class);
                    startActivity(iM);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
        }

    }

    private void showPopDate5() {
        View views = LayoutInflater.from(mContext).inflate(R.layout.fragment_layout_usermanager_showpop,null);

        LinearLayout liner_new = (LinearLayout) views.findViewById(R.id.liner_new);
        liner_new.setVisibility(View.VISIBLE);

        viewsback = views.findViewById(R.id.views);
        tv_chongzhi = (TextView) views.findViewById(R.id.fragment_home_textview_chongzhi);
        tv_sure = (TextView) views.findViewById(R.id.fragment_home_textview_sure);
        tv_huanbing = (TextView) views.findViewById(R.id.jibingfenlei_textview);
        tv_zhili = (TextView) views.findViewById(R.id.zhili_textview);
        tv_zhuzhen = (TextView) views.findViewById(R.id.zhuzhen_textview);
        tv_fourthName = (TextView) views.findViewById(R.id.tv_fourthName);
        tv_fifthName = (TextView) views.findViewById(R.id.tv_fifthName);

        gridView_zhili = (MyGridView) views.findViewById(R.id.fragment_zhiligridview);
        gridView_zhuzhen = (MyGridView) views.findViewById(R.id.fragment_home_zhuzhengridview);
        gridView_huanbing = (MyGridView) views.findViewById(R.id.fragment_home_huanbinggridview);
        gridview_fourth = (MyGridView) views.findViewById(R.id.gridview_fourth);
        gridview_fifth = (MyGridView) views.findViewById(R.id.gridview_fifth);


        viewsback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopWalk.dismiss();
            }
        });
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                filterList_fourth.clear();
                filterList_fifth.clear();

                FilterBean  beanFourth =  listBeans.get(fourth);
                FilterBean  beanFifth =  listBeans.get(fifth);

                //添加第4个筛选条件
                for(int i = 0 ; i < list_fourth.size() ; i++)
                {
                    if(list_fourth.get(i).isSelect())
                    {
                        addBean_fourth(beanFourth.getFilterId(),beanFourth.getFilterName(),beanFourth.getFilterType(),list_fourth.get(i).getItemId());
                    }
                }
                //添加第5个筛选条件
                for(int i = 0 ; i < list_fifth.size() ; i++)
                {
                    if(list_fifth.get(i).isSelect())
                    {
                        addBean_fifth(beanFifth.getFilterId(),beanFifth.getFilterName(),beanFifth.getFilterType(),list_fifth.get(i).getItemId());
                    }
                }

                YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
               // YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                showPopWalk.dismiss();
                loading();

            }
        });
        tv_chongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                gridViewAdapter_zhili.changeSelected(-1);
//                gridViewAdapter_zhuzhen.changeSelected(-1);
//                gridViewAdapter_huanbing.changeSelected(-1);
                for (int i=0;i<list_zhili.size();i++){
                    map_zhili.put(i,false);
                }
                gridViewAdapter_zhili.setIsSelected(map_zhili);
                for (int i=0;i<list_zhuzhen.size();i++){
                    map_zhuzhen.put(i,false);
                }
                gridViewAdapter_zhuzhen.setIsSelected(map_zhuzhen);
                for (int i=0;i<list_huanbing.size();i++){
                    map_huanbing.put(i,false);
                }
                gridViewAdapter_huanbing.setIsSelected(map_huanbing);
               // group = "";//
                group.removeAll(group);
                filterList_fenzhu.removeAll(filterList_fenzhu);
                filterList_zhili.removeAll(filterList_zhili);
                filterList_huanbing.removeAll(filterList_huanbing);


                //重置第4个筛选条件
                for(int i = 0 ; i < list_fourth.size() ; i++)
                {
                    list_fourth.get(i).setIsSelect(false);
                }
                //重置第5个筛选条件
                for(int i = 0 ; i < list_fifth.size() ; i++)
                {
                    list_fifth.get(i).setIsSelect(false);
                }
                fourthAdatper.notifyDataSetChanged();
                fifthAdatper.notifyDataSetChanged();
                filterList_fourth.clear();
                filterList_fifth.clear();

//                toastMsg("filterList_fenzhu: " +filterList_fenzhu.size()+",filterList_zhili:"+filterList_zhili.size()+",filterList_huanbing:"+filterList_huanbing.size());
//                removeFilterListItem(listBeans.get(2).getFilterId());
//                removeFilterListItem(listBeans.get(4).getFilterId());
//                removeFilterListItem(listBeans.get(1).getFilterId());
            }
        });

        gridViewAdapter_zhili = new UsermanagerGridViewAdapter(mContext,list_zhili);
        gridViewAdapter_zhuzhen = new UsermanagerGridViewAdapterZhuzhen(mContext,list_zhuzhen);
        gridViewAdapter_huanbing = new UsermanagerGridViewAdapterHuanBing(mContext,list_huanbing);
        fourthAdatper = new FilterAdapter(list_fourth,mContext);
        fifthAdatper = new FilterAdapter(list_fifth,mContext);

        gridView_zhili.setAdapter(gridViewAdapter_zhili);
        gridView_zhuzhen.setAdapter(gridViewAdapter_zhuzhen);
        gridView_huanbing.setAdapter(gridViewAdapter_huanbing);
        gridview_fourth.setAdapter(fourthAdatper);
        gridview_fifth.setAdapter(fifthAdatper);


        gridView_zhili.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Log.i("---mai_zhili--->","enter");
//                gridViewAdapter_zhili.changeSelected(i);
              //  listBeans.get(1).getFilterList();//诊断1 huanbing
//                        listBeans.get(2).getFilterList();//自理能力2
//                        listBeans.get(4).getFilterList();//主诊团队4
                if (map_zhili.get(i)){
                    map_zhili.put(i,false);
                }else {
                    map_zhili.put(i,true);
                }
                gridViewAdapter_zhili.setIsSelected(map_zhili);
                filterList_zhili.removeAll(filterList_zhili);
                FilterBean  bean =  listBeans.get(first);
//                Log.i("---mai_zhili--->",map_zhili.toString());
                for (int j=0;j<list_zhili.size();j++){
//                    Log.i("---mai_zhili--->","map_zhili:"+map_zhili.get(j));
                    if (map_zhili.get(j)){
                        addBean_zhili(bean.getFilterId(),bean.getFilterName(),bean.getFilterType(),bean.getFilterList().get(j).getItemId());
                    }
                }
            }
        });
        gridView_zhuzhen.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                gridViewAdapter_zhuzhen.changeSelected(i);
//                group = listBeans.get(4).getFilterList().get(i).getItemId();
                FilterBean  bean =  listBeans.get(second);
                if (map_zhuzhen.get(i)){
                    map_zhuzhen.put(i,false);
                }else {
                    map_zhuzhen.put(i,true);
                }
                filterList_fenzhu.removeAll(filterList_fenzhu);
               gridViewAdapter_zhuzhen.setIsSelected(map_zhuzhen);
                for (int j=0;j<list_zhuzhen.size();j++){

                    if (map_zhuzhen.get(j)){
                        group.add(listBeans.get(second).getFilterList().get(j).getItemId());
                        addBean_fenzhu(bean.getFilterId(),bean.getFilterName(),bean.getFilterType(),bean.getFilterList().get(j).getItemId());
                    }
                }
              //  addBean(bean.getFilterId(),bean.getFilterName(),bean.getFilterType(),bean.getFilterList().get(i).getItemId());
            }
        });
        gridView_huanbing.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                gridViewAdapter_huanbing.changeSelected(i);
                FilterBean  bean =  listBeans.get(third);
                if (map_huanbing.get(i)){
                    map_huanbing.put(i,false);
                }else {
                    map_huanbing.put(i,true);
                }
                gridViewAdapter_huanbing.setIsSelected(map_huanbing);
                filterList_huanbing.removeAll(filterList_huanbing);
                for (int j=0;j<list_huanbing.size();j++){
                    if (map_huanbing.get(j)){
                        addBean_huanbing(bean.getFilterId(),bean.getFilterName(),bean.getFilterType(),bean.getFilterList().get(j).getItemId());
                    }
                }
            }
        });

        //第四个gridView 点击事件
        gridview_fourth.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                boolean isSelect = list_fourth.get(position).isSelect();
                list_fourth.get(position).setIsSelect(!isSelect);
                fourthAdatper.notifyDataSetChanged();
            }
        });

        //第五个gridView 点击事件
        gridview_fifth.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                boolean isSelect = list_fifth.get(position).isSelect();
                list_fifth.get(position).setIsSelect(!isSelect);
                fifthAdatper.notifyDataSetChanged();
            }
        });

//        showPopWalk = new PopupWindow();
        showPopWalk = new  PopupWindow(views, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,true);
        showPopWalk.setOutsideTouchable(true);
        showPopWalk.setTouchable(true);
        showPopWalk.setFocusable(true);
        showPopWalk.setBackgroundDrawable(new ColorDrawable(0x00000000));
        showPopWalk.setAnimationStyle(R.style.popwindow_anim_right);
        showPopWalk.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(getActivity());
            }
        });
//        showPopWalk.showAtLocation(ll_title, Gravity.RIGHT,0,0);
    }
    private void addBean_fenzhu(String filterId,String filterName,String filterType,String itemId) {
        //removeFilterList_fenzhuItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList_fenzhu.add(bean);
    }
    private void addBean_zhili(String filterId,String filterName,String filterType,String itemId) {
        //removeFilterList_zhiliItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList_zhili.add(bean);
//        Log.i("---mai_zhili--->","filterList_zhili:"+filterList_zhili.size());
    }
    private void addBean_huanbing(String filterId,String filterName,String filterType,String itemId) {
       // removeFilterList_huanbingItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList_huanbing.add(bean);
    }
    //添加第四个筛选
    private void addBean_fourth(String filterId,String filterName,String filterType,String itemId) {
        // removeFilterList_huanbingItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList_fourth.add(bean);
    }
    //添加第五个筛选
    private void addBean_fifth(String filterId,String filterName,String filterType,String itemId) {
        // removeFilterList_huanbingItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList_fifth.add(bean);
    }


    private void addBean(String filterId,String filterName,String filterType,String itemId) {
        removeFilterListItem(filterId);
        FilterPatientBean bean = new FilterPatientBean();
        bean.setDate("");
        bean.setDateKind("");
        bean.setFilterId(filterId);
        bean.setFilterName(filterName);
        bean.setFilterType(filterType);
        bean.setItemId(itemId);
        filterList.add(bean);
    }


    private void showPopDate4() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                            display4TV.setText(display4Default);
                        }
                        date = "";
                        dateKind = "";
                        removeFilterListItem(display4Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display4Id);
                        bean.setFilterName(display4Default);
                        bean.setFilterType(display4Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                      //  Log.i("------------>","fenzhu:dfsdfsf"+filterList_fenzhu.size()+"huangbing:"+filterList_huanbing.size()+"zhili:"+filterList_zhili.size()+"");
                       // YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    loading();
                    removeFilterListItem(display4Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display4Id);
                    bean.setFilterName(display4Default);
                    bean.setFilterType(display4Type);
                    bean.setItemId("");

                    filterList.add(bean);
                  //  Log.i("-----dd------->","fenzhu:"+filterList_fenzhu.size()+"huangbing:"+filterList_huanbing.size()+"zhili:"+filterList_zhili.size()+"");
                 //   YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                    YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display4TV.setText(displayDate);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display4TV.setText(displayTime);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                    }
                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate3() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        }
                        date = "";
                        dateKind = "";
                        removeFilterListItem(display3Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display3Id);
                        bean.setFilterName(display3Default);
                        bean.setFilterType(display3Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    loading();
                    removeFilterListItem(display3Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display3Id);
                    bean.setFilterName(display3Default);
                    bean.setFilterType(display3Type);
                    bean.setItemId("");

                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                    } else {
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate2() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        }
                        date = "";
                        dateKind = "";

                        removeFilterListItem(display2Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display2Id);
                        bean.setFilterName(display2Default);
                        bean.setFilterType(display2Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    removeFilterListItem(display2Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId("");

                    loading();
                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                    } else {
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate1() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        }
                        date = "";
                        dateKind = "";

                        removeFilterListItem(display2Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display2Id);
                        bean.setFilterName(display2Default);
                        bean.setFilterType(display2Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                       // YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    removeFilterListItem(display2Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId("");

                    loading();
                    filterList.add(bean);
                  //  YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                    YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display1TV.setText(displayDate);
                        display1IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display1TV.setText(displayTime);
                        display1IV.setImageResource(R.mipmap.tab_arrow);
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);

    }


    @Override
    public void onSelected(String type, UserManagerBean info) {
        if ("monitor".equals(type)) {
            Intent intent = new Intent(getActivity(), MonitorChart1Activity.class);
            intent.putExtra("patientId", info.getPatientId());
            intent.putExtra("isFromList", true);
            startActivity(intent);
        }
        if ("remind".equals(type)) {
//            Intent intent = new Intent(getActivity(), NoticeActivity.class);
//            intent.putExtra("patientId", info.getPatientId());
//            startActivity(intent);
            Intent intent = new Intent(getActivity(), PatientBetterPlanActivity.class);
            intent.putExtra("patientId", info.getPatientId());
            startActivity(intent);
        } else if ("chat".equals(type)) {
            Intent intent = new Intent(getActivity(), ChatFragmentActivity.class).
                    putExtra(EaseConstant.EXTRA_USER_ID, "ejh" + info.getTel()).putExtra("name", info.getName());
            startActivity(intent);
        }
        if ("item".equals(type)) {
            Intent intent = new Intent(getActivity(), PatientInfoActivity.class);
            intent.putExtra("patientId", info.getPatientId());
            startActivity(intent);
        }
        YiJiaHuNetWorkUtils.userTalking(info.getPatientId(), handler);
    }

    @Override
    public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
        isLoadMore = false;
        pageIndex = 1;
        pageSize=15;
//        userManagerInfoList.clear();
      //  YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
        YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
    }

    @Override
    public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {

        if (userManagerInfoList.size() == totalCount) {
            isLoadMore = false;
            refreshLayout
                    .loadmoreFinish(PullToRefreshLayout.SUCCEED);
            return;
        }

        isLoadMore = false;
        pageSize+=15;
       // pageIndex++;
        YiJiaHuNetWorkUtils.getPatientFilterNewResultList(filterList,filterList_fenzhu,filterList_huanbing,filterList_zhili,filterList_fourth,filterList_fifth,"1",group, "", pageIndex, pageSize, handler);
        //YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

    }

    public static UserManagerFragment newInstance() {

        return new UserManagerFragment();
    }


    public void setAllAdapterDao()
    {
        adapter.setHospitalStatus(loginInfo.getDepartmentId());
        adapter.notifyDataSetChanged();
    }
}
